package com.youyicloud.api;

import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.zuul.web.ZuulHandlerMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youyicloud.constants.Constants;
import com.youyicloud.service.RefreshRouteService;
import com.youyicloud.vo.ResponseBodyEntity;

@RestController
public class AdminApi {

	@Autowired
	public RefreshRouteService refreshRouteService;
	@Autowired
	public ZuulHandlerMapping zuulHandlerMapping;

	@GetMapping("/refreshRoute")
	public ResponseBodyEntity refresh() {
		refreshRouteService.refreshRoute();
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		responseBodyEntity.setData(null);
		responseBodyEntity.setMsg("刷新成功");
		responseBodyEntity.setState(Constants.SUCCEED);
		return responseBodyEntity;
	}

	@RequestMapping("/watchRoute")
	public ResponseBodyEntity watchNowRoute() {
		// 可以用debug模式看里面具体是什么
		Map<String, Object> handlerMap = zuulHandlerMapping.getHandlerMap();
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		responseBodyEntity.setData(handlerMap);
		responseBodyEntity.setMsg("获取路由列表成功");
		responseBodyEntity.setState(Constants.SUCCEED);
		return responseBodyEntity;
	}

}
